package com.example.fashionshoes.controller;

import com.example.fashionshoes.pojo.dto.GoodsPageDTO;
import com.example.fashionshoes.pojo.po.CategoryGoods;
import com.example.fashionshoes.pojo.po.Result;
import com.example.fashionshoes.pojo.vo.GoodsDetailVO;
import com.example.fashionshoes.pojo.vo.GoodsPageVO;
import com.example.fashionshoes.service.CategoryService;
import com.example.fashionshoes.service.GoodsService;
import jakarta.annotation.Resource;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;
    @Resource
    private CategoryService categoryService;

    /**
     * 获取指定商品包含分类
     * @param id 商品id
     * @return 指定商品
     */
    @GetMapping
    public Result<GoodsDetailVO> getGoodsDetail(@Param("id") Integer id){
        GoodsDetailVO goodsDetailVO = categoryService.getGoodsDetail(id);
        return Result.success(goodsDetailVO);
    }

    /**
     * 获取所有商品
     * @return 所有商品包含分类id
     */
    @GetMapping("/list")
    public Result<List<CategoryGoods>> list(){
        List<CategoryGoods> goodsList = categoryService.getList();
        return Result.success(goodsList);
    }

    /**
     * 获取商品库存
     * @param id 商品id
     * @return 商品库存
     */
    @GetMapping("/stock/{id}")
    public Result<Object> getStock(@PathVariable("id")Integer id){
        return null;
    }

    /**
     * 获取热榜商品
     * @param id 商品id
     * @param type 1为24小时榜，2为周榜
     * @param limit 商品数量
     * @return 热榜商品
     */
    @GetMapping("/hot")
    public Result<List<GoodsDetailVO>> getHotGoods(@Param("id") Integer id,@Param("type") Integer type,@Param("limit") Integer limit){
        List<GoodsDetailVO> goodsDetailVOList = goodsService.getHotGoods(id,type,limit);
        return Result.success(goodsDetailVOList);
    }

    /**
     * 根据关键词查询商品
     * @param goodsPageDTO 关键词、分页数据等
     * @return 对应商品
     */
    @PostMapping("/search")
    public Result<GoodsPageVO> search(@RequestBody GoodsPageDTO goodsPageDTO){
        GoodsPageVO pageVO = goodsService.search(goodsPageDTO);
        return Result.success(pageVO);
    }

}
